﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Logistics_Service.DTO;
using Logistics_Service.DAO;

namespace Logistics_Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class LogisticsService : ILogisticsService
    {
        //---------Khach hang--------------
        public KhachHangDTO[] DanhSachKhachHang()
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            KhachHangDAO khd = new KhachHangDAO();
            return khd.DanhSachKhachHang();
        }
        public bool ThemKhachHang(string ten, string user, string matkhau, string cmnd, string sdt, string email, string ngaysinh, string diachi)
        {
            //DateTime ndk = DateTime.Parse(ngaydangky.ToString());
            DateTime ns = DateTime.Parse(ngaysinh.ToString());
            KhachHangDAO khd = new KhachHangDAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            return khd.ThemKhachHang(ten, user, matkhau, cmnd, sdt, email ,ns, diachi);
        }
        public bool XoaKhachHang(string ma)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            KhachHangDAO khd = new KhachHangDAO();
            return khd.XoaKhachHang(ma);
        }
        public bool CapNhatKhachHang(string ma, string ten, string user, string matkhau, string cmnd, string sdt, string email, string ngaydangky, string xacnhan, string ngaysinh, string diachi)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            DateTime ndk = DateTime.Parse(ngaydangky.ToString());
            DateTime ns = DateTime.Parse(ngaysinh.ToString());
            KhachHangDAO khd = new KhachHangDAO();
            return khd.CapNhatKhachHang(ma, ten, user, matkhau, cmnd, sdt, email, ndk, xacnhan, diachi, ns);
        }
        public KhachHangDTO LoginKH(string username, string pass)
        {
            DangNhapDAO dn = new DangNhapDAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            return dn.LoginKH(username,pass);

        }

        //..........Tuyen Duong ..........
        public TuyenDuongDTO[] DanhSachTuyenDuong()
        {
            TuyenDuongDAO td = new TuyenDuongDAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            return td.DanhSachTuyenDuong();
        }
        public float TimSoKm(string dd, string dc)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            TuyenDuongDAO td = new TuyenDuongDAO();
            return td.TimSoKm(dd,dc);
        }



        //---------LoaiVanChuyen-----------
        public LoaiVanChuyenDTO[] DanhSachLoaiVanChuyen()
        {           
            LoaiVanChuyenDAO lvc = new LoaiVanChuyenDAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            return lvc.DanhSachLoaiVanChuyen();
        }

        //............Xe.......................
        public XeDTO[] DanhSachXe()
        {
            XeDAO xe = new XeDAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            return xe.DanhSachXe();
        }

        //-----------Chuc vu-------------
        public ChucVuDTO[] DanhSachChucVu()
        {
            ChucVuDAO cv = new ChucVuDAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            return cv.DanhSachChucVu(); 
        }

        //------------Loai nhan vien -----------
        public LoaiNhanVienDTO[] DanhSachLoaiNhanVien()
        {
            LoaiNhanVienDAO lnv = new LoaiNhanVienDAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            return lnv.DanhSachLoaiNhanVien();
        }


        //----------- nhan vien -----------
        public NhanVienDTO[] DanhSachNhanVien()
        {
            NhanVienDAO lnv = new NhanVienDAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            return lnv.DanhSachNhanVien();
        }

        //----------- chi nhanh -----------
        public ChiNhanhDTO[] DanhSachChiNhanh()
        {
            ChiNhanhDAO cn = new ChiNhanhDAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            return cn.DanhSachChiNhanh();
        }

        public bool ThemChiNhanh(string ten, string diachi, string sdt, string matinhthanh)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");           
            ChiNhanhDAO cn = new ChiNhanhDAO();
            return cn.ThemChiNhanh(ten,diachi,sdt,matinhthanh);
        }
        

        //----------- tinh thanh -----------
        public TinhThanhDTO[] DanhSachTinhThanh()
        {
            TinhThanhDAO tt = new TinhThanhDAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            return tt.DanhSachTinhThanh();
        }



        public DiaDiemDTO[] DanhSachDiaDiem()
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            DiaDiemDAO dao = new DiaDiemDAO();
            return dao.DanhSachDiaDiem();
        }

        public LichVanChuyenDTO[] DanhSachLichVanChuyen()
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            LichVanChuyenDAO dao = new LichVanChuyenDAO();
            return dao.DanhSachLichVanChuyen();
        }
        //-------------------Goi Hang------------------
        public GoiHangDTO GoiHang(string magoihang)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            GoiHangDAO dao = new GoiHangDAO();
            return dao.GoiHang(magoihang);
        }
        public GoiHangDTO[] DanhSachGoiHang(string makhachhang)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            GoiHangDAO dao = new GoiHangDAO();
            return dao.DanhSachGoiHang(makhachhang);
        }
        public bool CapNhatGoiHang(string magoihang, string vitrikho)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            GoiHangDAO dao = new GoiHangDAO();
            return dao.CapNhatGoiHang(magoihang,vitrikho);
        }
        //---------------Don Hang---------------------
        public bool ThemDonHang(string ngaydat,string ngaylay,string dcLay,string maloaivc,string tenNN,string cmnd,string sdt,string dcNN,string magh,string makh,string tenchuthe,string sotk,string tongtien)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            DonHangDTO dh = new DonHangDTO();
            dh.MaDonHang = "1";
            dh.NgayDat = DateTime.Parse(ngaydat.ToString());
            dh.NgayLayHang = DateTime.Parse(ngaylay.ToString());
            dh.DiaChiLayHang = dcLay;
            dh.MaLoaiVanChuyen = maloaivc;
            dh.TenNguoiNhan = tenNN;
            dh.CMND = cmnd;
            dh.SDT = sdt;
            dh.DiaChiNguoiNhan = dcNN;
            dh.MaGoiHang = magh;
            dh.MaKhachHang = makh;
            dh.TenChuThe = tenchuthe;
            dh.SoTaiKhoan = sotk;
            dh.TongTien = float.Parse(tongtien);
            dh.TinhTrang = 1;
            dh.DaXoa = true;
            dh.LoaiDatHang = "truc tuyen";
            DonHangDAO dhDAO = new DonHangDAO();
            return dhDAO.ThemDonHang(dh);
        }
        public DSDonHangDTO[] DanhSachDonHangTheoKhachHang(string makh)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            DonHangDAO dhDao = new DonHangDAO();
            return dhDao.DanhSachDonHang(makh);
        }
        public DSDonHangDTO[] DanhSachDonHangTheoKhachHangChuaThucHien(string makh)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            DonHangDAO dhDao = new DonHangDAO();
            return dhDao.DanhSachDonHangDangThucHien(makh);
        }
        public DSDonHangDTO[] ChiTietDonHang(string madonhang)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            DonHangDAO dhDao = new DonHangDAO();
            return dhDao.ChiTietDonHang(madonhang);
        }
        //---------BangGia----------------
        public BangGiaDTO[] GiaTheoKm(string sokm)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            BangGiaDAO bgDAO = new BangGiaDAO();
            return bgDAO.GiaTheoKm(sokm);
        }

    }
}
